<template>
  <div>
    <!-- 这个组件用来展示左侧的导航菜单 -->
    <el-menu
      :default-active="defaultActive"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      unique-opened
      router
    >
      <el-menu-item index="/home">
        <i class="el-icon-s-grid"></i>
        <span slot="title">首页</span> 
      </el-menu-item>
      <el-submenu v-for="item in $store.getters.getUserInfo.menus" :key='item.id' :index="item.id.toString()">
        <template slot="title">
          <i :class="item.icon"></i>
          <span>{{item.title}}</span>
        </template>
        <el-menu-item v-for="menu in item.children" :key="menu.id" :index="menu.url">{{menu.title}}</el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>

export default {
  data() {
    return {
      defaultActive: "/home",
      navlist:[]
    };
  },
  mounted() {
    //console.log(this.$route, "路由对象");
    //重新给默认选中状态赋值，让其与浏览器地址栏一致,保持你的选中状态
    this.defaultActive = this.$route.path;
    // if(sessionStorage.getItem('userinfo')){
    //   this.navlist = JSON.parse(sessionStorage.getItem('userinfo')).menus
    // }
  },
};
</script>

<style scoped>
.el-menu {
  min-height: 600px;
}
</style>